package com.tulink.yichutu.controller.wxpay;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tulink.yichutu.biz.GoodsBiz;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.tulink.yichutu.common.utils.DataResult;

import com.tulink.yichutu.entity.WxVipGoodsEntity;
import com.tulink.yichutu.service.WxVipGoodsService;



/**
 * 商品表
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2021-10-04 02:02:48
 */
@Controller
@RequestMapping("/")
public class WxVipGoodsController {
    @Autowired
    private WxVipGoodsService wxVipGoodsService;
    @Autowired
    private GoodsBiz goodsBiz;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/wxVipGoods")
    public String wxVipGoods() {
        return "wxvipgoods/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("wxVipGoods/add")
    @RequiresPermissions("wxVipGoods:add")
    @ResponseBody
    public DataResult add(@RequestBody WxVipGoodsEntity wxVipGoods){
        wxVipGoodsService.save(wxVipGoods);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("wxVipGoods/update")
    @RequiresPermissions("wxVipGoods:update")
    @ResponseBody
    public DataResult update(@RequestBody WxVipGoodsEntity wxVipGoods){
        wxVipGoodsService.updateById(wxVipGoods);
        return DataResult.success();
    }

    @ApiOperation(value = "发布商品")
    @PostMapping("wxVipGoods/publish")
    @RequiresPermissions("wxVipGoods:update")
    @ResponseBody
    public DataResult publish(){
        goodsBiz.initCache();
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("wxVipGoods/listByPage")
    @RequiresPermissions("wxVipGoods:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody WxVipGoodsEntity wxVipGoods){
        Page page = new Page(wxVipGoods.getPage(), wxVipGoods.getLimit());
        LambdaQueryWrapper<WxVipGoodsEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(WxVipGoodsEntity::getId, wxVipGoods.getId());
        IPage<WxVipGoodsEntity> iPage = wxVipGoodsService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
